#!/bin/sh
if [[ "X$1" == "X" ]]
then
	month=`date +%Y%m --date '-1 day'`
else
	month=$1
fi
echo $month
dataDir=/work/opt/fourthinfo/zhaoxiang/zp_user_report
tableName="t_zhaopin_vip_stat_$month"
droptable="drop table $tableName;"
creattable='CREATE TABLE if not exists `'$tableName'` (
  `stat_date` date NOT NULL DEFAULT "0000-00-00" COMMENT "统计日期",
  `user_id` bigint(20) NOT NULL DEFAULT "0" COMMENT "用户id",
  `order_source` varchar(20) DEFAULT NULL COMMENT "订单来源",
  `vip_count` int(11) DEFAULT NULL COMMENT "网邻通次数",
  `post_count` int(11) DEFAULT NULL COMMENT "发帖次数",
  `valid_post_count` int(11) DEFAULT NULL COMMENT "有效发帖次数",
  `post_pv` int(11) DEFAULT NULL COMMENT "帖子浏览次数pv", 
  `promote_count` int(11) DEFAULT NULL COMMENT "推广次数",
  `refresh_count` int(11) DEFAULT NULL COMMENT "刷新次数",
  `login_count` int(11) DEFAULT NULL COMMENT "登录次数",
  `precise_count` int(11) DEFAULT NULL COMMENT "精准消费次数",
  `precise_amount` double DEFAULT NULL COMMENT "精准消费金额",
  `top_count` int(11) DEFAULT NULL COMMENT "置顶次数",
  `top_amount` double DEFAULT NULL COMMENT "置顶消费金额",
  `zhineng_count` int(11) DEFAULT NULL COMMENT "智能次数",
  `zhineng_amount` double DEFAULT NULL COMMENT "智能消费金额",
  `download_count` int(10) DEFAULT NULL COMMENT "简历下载次数",
  `download_amount` double DEFAULT NULL COMMENT "简历下载金额",
  `download_pkg_count` int(10) DEFAULT NULL COMMENT "简历下载套餐次数",
  `download_pkg_amount` double DEFAULT NULL COMMENT "简历下载套餐金额",
   `account_type` smallint DEFAULT NULL COMMENT "账户类型，0:字母账户，1:非0元账户"
) ENGINE=BRIGHTHOUSE DEFAULT CHARSET=utf8 COMMENT="招聘会员数据";'
mysql -h10.5.20.26 -P5029 -uhuangliang -pDcUsZkvcj8H8efPbpy -D data_bi -e "$droptable""$creattable"
if [ $? -ne 0 ]
then 
	exit 1
fi
echo  "table $tableName created!"
for f in $(ls $dataDir/zhaopin_vip_stat_$month*)
do
	loaddata="load data local infile '$f' into table $tableName CHARACTER SET utf8 fields terminated by '\t' LINES TERMINATED BY '\n';"
	echo $loaddata
	echo $loaddata | mysql --auto-rehash -h10.5.20.26 -P5029 -uhuangliang -pDcUsZkvcj8H8efPbpy -D data_bi
done
